﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using CQIE.TES.IDAL;
using CQIE.TES.IService;
using CQIE.TES.Model;
using Newtonsoft.Json.Linq;

namespace CQIE.TES.Service
{
    public class StudentService:IStudentService
    {
        private readonly IStudentDAL _dal;

        public StudentService(IStudentDAL dal)
        {
            this._dal = dal;
        }
        /// <summary>
        /// 分页、查询
        /// </summary>
        /// <param name="pageNum"></param>
        /// <param name="pageSize"></param>
        /// <param name="search"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public List<Student> GetStudentsPage(int pageNum, int pageSize, string search, out int count)
        {
            return _dal.GetStudentsPage(pageNum-1, pageSize, search,out count);
        }
        //禁用
        [Obsolete]
        public List<Student> SearchStudent(string nameSearch)
        {
            return _dal.SearchStudent(nameSearch);
        }
        /// <summary>
        /// 逻辑删除学生
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteStudent(int id)
        {
            return _dal.DeleteStudent(id);
        }
        public void Test()
        {
            _dal.Test();
        }
        /// <summary>
        /// 添加学生
        /// </summary>
        /// <param name="id"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public void UpdateStudent([FromBody] JObject data)
        {
            _dal.UpdateStudent(data);
        }
        /// <summary>
        /// 重置学生密码
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool ResetPassWord(int id)
        {
            return _dal.ResetPassWord(id);
        }

        /// <summary>
        /// 编辑学生
        /// </summary>
        /// <param name="id">通过id找到学生</param>
        /// <param name="data">前端返回的json格式的数据</param>
        /// <returns></returns>
        public bool EditStudent(int id,string studentName,int sex, bool isFreeze, string studentNumber,string passWord,int classID)
        {
            try
            {
                _dal.EditStudent(id, studentName, sex, isFreeze, studentNumber, passWord, classID);
                return true;
            }
            catch
            {

                return false;
            }
        }

        public Student Login(string username, string password)
        {
            return _dal.Login(username, password);
        }

        public Student Get(int sid)
        {
            return _dal.Get(sid);
        }
    }
}
